#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int longestSubsequence(vector<int>& arr, int dif) {
        int n = arr.size();
        int ret = 1;
        unordered_map<int, int>hashi;
        hashi[arr[0]] = 1;
        for (int i = 1; i < n; i++)
        {
            hashi[arr[i]] = hashi[arr[i] - dif] + 1;
            ret = max(ret, hashi[arr[i]]);
        }
        return ret;
    }
};